package cn.gok.service.impl;

import cn.gok.dao.UserDao;
import cn.gok.entity.User;
import cn.gok.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import sun.security.provider.MD5;

/**
 * @author shikundai
 * @date 2021/3/21
 * @time 14:03
 * @description
 */
@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;
    @Override
    public User getUser(String name) {
        User user=new User();
        user.setName(name);
        QueryWrapper<User> userQueryWrapper=new QueryWrapper<>();
        userQueryWrapper.setEntity(user);

        User user1=userDao.selectOne(userQueryWrapper);
        return user1;
    }

    @Override
    public int addUser(User user) {
        /*
        * 对密码进行加密
        * 采用MD5hash
        * */
        String psw=new Md5Hash(user.getPsw()).toString();
        user.setPsw(psw);
        //插入到数据库
        return userDao.insert(user);
    }
}
